home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / views.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  7KB  |  296 lines

  1. /* --------------------------------- views.c -------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Show all visual displays
  8. */
  9.  
  10. #include "plane.h"
  11.  
  12.  
  13. static MENU FAR MenuView[] = {
  14.     {'f', "front"},        /*  0 */
  15.     {'n', "none"},        /*  1 */
  16.     {'a', "rear"},        /*  2 */
  17.     {'m', "map"},        /*  3 */
  18.     {'r', "radar"},        /*  4 */
  19.     {'t', "target"},    /*  5 */
  20.     {'p', "pan"},        /*  6 */
  21.     {'g', "gaze"},        /*  7 */
  22.     {'c', "chase"},        /*  8 */
  23.     {'o', "follow"},    /*  9 */
  24.     {'h', "hud"},        /* 10 */
  25.     {'u', "up-front"},    /* 11 */
  26.     {'P', "panel"},        /* 12 */
  27.     {'R', "right"},        /* 13 */
  28.     {'L', "left"},        /* 14 */
  29.     {'s', "stores"},    /* 15 */
  30.     {'l', "lamps"},        /* 16 */
  31.     {'M', "mirror"},    /* 17 */
  32. {'\0', 0}};
  33.  
  34. /* Select external view mode
  35. */
  36.  
  37. extern int FAR
  38. menu_view (int sel)
  39. {
  40.     sel = menu_open (MenuView, sel);
  41.     if (MENU_FAILED != sel)
  42.         menu_close ();
  43.     return (sel);
  44. }
  45.  
  46. LOCAL_FUNC void NEAR
  47. ident (int id, int orgx, int orgy, int maxx, int maxy, int ss)
  48. {
  49.     int    bss, i, l;
  50.     char    *p;
  51.  
  52.     if (st.flags1 & SF_IDENT) {
  53.         i = id ? st.hdd[id-1].type : st.extview;
  54.         p = MenuView[i].text;
  55.         l = strlen (p);
  56.         bss = ss*4;
  57.         if (bss > 64)
  58.             bss = 64;
  59.         if (bss > maxx/l)
  60.             bss = maxx/l;
  61.         stroke_num (orgx-bss*l/2, orgy, (long)id, bss, ST_INFO);
  62.         stroke_str (orgx-bss*l/2, orgy+bss, p, bss, ST_INFO);
  63.     } else if (!(st.flags & SF_BLANKER) && (st.flags1 & SF_WIDENT)) {
  64.         i = id ? st.hdd[id-1].type
  65.                : (st.flags1&SF_EXTVIEW ? st.extview: -1);
  66.         if (i >= 0) {
  67.             p = MenuView[i].text;
  68.             l = stroke_size (p, ss);
  69.             stroke_str (orgx+maxx-l, orgy-maxy+ss, p, ss, ST_HFG);
  70.         }
  71.     }
  72. }
  73.  
  74. /* Get window dimentions.
  75. */
  76. extern void FAR
  77. get_area (VIEW *view, int *orgx, int *orgy, int *maxx, int *maxy)
  78. {
  79.     int        px;
  80.     VIEWPORT    *vp;
  81.  
  82. /* Calculate paralax.
  83. */
  84.     if (F(vp = VP))
  85.         vp = CVIEW->viewport;
  86.     px = muldiv (vp->z, vp->shift, vp->distz);    /* normalized */
  87.     px = muldiv (VS->sizex, px, vp->maxx) / 2;    /* pixels */
  88.     px = fmul (px, VW->maxx) + (px<0);
  89.  
  90.     if (orgx)
  91.         *orgx = fmul (VW->orgx, VS->sizex) + VS->minx + px;
  92.     if (orgy)
  93.         *orgy = fmul (VW->orgy, VS->sizey) + VS->miny;
  94.     if (maxx)
  95.         *maxx = fmul (VW->maxx, VS->sizex) - 1 - iabs(px);
  96.     if (maxy)
  97.         *maxy = fmul (VW->maxy, VS->sizey) - 1;
  98. }
  99.  
  100. /* Get largest square that fits in window.
  101. */
  102. extern void FAR
  103. get_square (VIEW *view, int maxx, int maxy, int *sizex, int *sizey)
  104. {
  105.     int    sx, sy;
  106.  
  107.     sx = muldiv (VS->device->lengx, maxx, VS->device->sizex);
  108.     sy = muldiv (VS->device->lengy, maxy, VS->device->sizey);
  109.  
  110.     if (sx > sy) {        /* wide window */
  111.         sx = muldiv (maxx, sy, sx);
  112.         sy = maxy;
  113.     } else {        /* high window */
  114.         sy = muldiv (maxy, sx, sy);
  115.         sx = maxx;
  116.     }
  117.     *sizex = sx;
  118.     *sizey = sy;
  119. }
  120.  
  121. /* this is the main display dispatcher.
  122. */
  123. extern void FAR
  124. show_main (VIEW *view, OBJECT *pov, int type, int special)
  125. {
  126.     int    orgx, orgy, maxx, maxy, ss;
  127.     OBJECT    *p;
  128.  
  129.     if (IS_PLANE(CV))
  130.         p = CV;
  131.     else
  132.         p = CC;
  133.     if (!p)
  134.         return;
  135.  
  136.     get_area (view, &orgx, &orgy, &maxx, &maxy);
  137.     if (maxx <= 0)
  138.         return;
  139.  
  140.     ss = fmul (maxx, FCON (0.03));
  141.     ss = muldiv (ss, st.StFontSize, 8);
  142.     ss = (ss+1)&~1;                    /* make it even */
  143.     if (ss < 8)
  144.         ss = 8;
  145.  
  146.     if (special & 1)
  147.         show_hud (view, pov, p, orgx, orgy, maxx, maxy, type);
  148.  
  149. /* digital panel
  150. */
  151.     if ((HDT_FRONT==type && (st.flags & SF_MAIN) && (EX->hud1 & HUD_PANEL))
  152.         || HDT_PANEL == type)
  153.         show_panel (view, p, maxx, maxy, orgx, orgy, ss);
  154.  
  155. /* status info. This text is shown over the whole screen. It will not show if
  156.  * there is an active UPFRONT HDD.
  157. */
  158.     screen_info (view, orgx, orgy, maxx, maxy, ss, type);
  159.  
  160.     if (st.flags & SF_MAIN)
  161.         ident (0, orgx, orgy, maxx, maxy, ss);
  162. }
  163.  
  164. extern int FAR
  165. scenery (int type)
  166. {
  167.     return (HDT_NONE != type && HDT_HUD != type && HDT_UPFRONT != type &&
  168.         HDT_PANEL != type && HDT_LAMPS != type);
  169. }
  170.  
  171. LOCAL_FUNC void NEAR
  172. show_view (VIEW *cv, int type, int special)
  173. {
  174.     OBJECT    *pov;
  175.     E_PLANE    *ecv;
  176.     int    t, vr, wr, smaxx, smaxy;
  177.     Ushort    shud, shud1;
  178.  
  179.     if (!cv)
  180.         return;
  181.  
  182.     t = (HDT_HUD == type) ? HDT_FRONT : type;
  183.     if (F(pov = get_viewer (t)) || !pov->viewport)
  184.         return;
  185.  
  186.     ecv = IS_PLANE(CV) ? EE(CV) : 0;
  187.     cv->viewport = pov->viewport;
  188.     smaxx = cv->viewport->maxx;
  189.     smaxy = cv->viewport->maxy;
  190.     if (ecv) {
  191.         shud  = ecv->hud;
  192.         shud1 = ecv->hud1;
  193.         ecv->hud  &= ~(HUD_ON|HUD_CURSOR|HUD_RETICLE);
  194.         ecv->hud1 &= ~(HUD_VALARM|HUD_PANEL);
  195.     } else
  196.         shud = shud1 = 0;    /* avoid compiler warning */
  197.  
  198. /* Adjust aspect ratio. All viewports use the same aspect ratio as the main
  199.  * window, now adjust the viewport for the actual window.
  200.  * The 1/4 scaling is done to allow handling high aspect ratios.
  201. */
  202.     if (!(st.flags & SF_MAIN)) {
  203.         vr = muldiv (FONE/4, cv->viewport->maxx, cv->viewport->maxy);
  204.         wr = muldiv (FONE/4, cv->window->maxx,   cv->window->maxy);
  205.         wr = muldiv (wr, cv->screen->device->lengx,
  206.                         cv->screen->device->lengy);
  207. #if 0
  208.         if (vr > wr)    /* viewport too wide */
  209.             cv->viewport->maxx = muldiv (cv->viewport->maxx,
  210.                             wr, vr);
  211.         else        /* viewport too hight */
  212.             cv->viewport->maxy = muldiv (cv->viewport->maxy,
  213.                             vr, wr);
  214. #else
  215.         if (vr > wr)    /* viewport wider than window */
  216.             cv->viewport->maxy = muldiv (cv->viewport->maxy,
  217.                             vr, wr);
  218.         else        /* viewport higher than window */
  219.             cv->viewport->maxy = muldiv (cv->viewport->maxy,
  220.                             vr, wr);
  221. #endif
  222.     }
  223.  
  224.     if (scenery (type)) {
  225.         show_sky (cv, pov);
  226.         objects_show (0, cv, pov, 0, 0, 0);
  227.     }
  228.  
  229.     show_main (cv, pov, type, special);
  230.  
  231.     cv->viewport->maxx = smaxx;
  232.     cv->viewport->maxy = smaxy;
  233.     if (ecv) {
  234.         ecv->hud  = shud;
  235.         ecv->hud1 = shud1;
  236.     }
  237.  
  238.     cv->viewport = 0;
  239. }
  240.  
  241. extern void FAR
  242. show_hdd (void)
  243. {
  244.     int    i, orgx, orgy, maxx, maxy, ss, type;
  245.     long    t27;
  246.     VIEW    *v;
  247.  
  248.     t27 = STATS_TIME3D;
  249.     Tm->Interval (TMR_START, 0L);
  250.     for (i = 0; i < NHDD; ++i) {
  251.         if (!(st.hdd[i].flags & HDF_ON))
  252.             continue;
  253.  
  254.         v = &st.hdd[i].view;
  255.         orgx = fmul (v->window->orgx, v->screen->sizex)
  256.             + v->screen->minx;
  257.         orgy = fmul (v->window->orgy, v->screen->sizey)
  258.             + v->screen->miny;
  259.         maxx = fmul (v->window->maxx, v->screen->sizex) - 1;
  260.         maxy = fmul (v->window->maxy, v->screen->sizey) - 1;
  261.         ss = fmul (maxx, FCON (0.04));
  262.         ss = muldiv (ss, st.StFontSize, 8);
  263.         ss = (ss+1)&~1;        /* make it even */
  264.         if (ss < 8)
  265.             ss = 8;
  266.  
  267.         switch (type = st.hdd[i].type) {
  268.         case HDT_NONE:
  269.             break;
  270.         case HDT_UPFRONT:
  271.             if (hdd_menu (v, orgx, orgy, maxx, maxy))
  272.                 screen_info (v, orgx, orgy, maxx, maxy, ss,
  273.                     st.hdd[i].type);
  274.             break;
  275.         case HDT_PANEL:
  276.             show_panel (v, CC, maxx, maxy, orgx, orgy, ss);
  277.             break;
  278.         case HDT_STORES:
  279.             show_stores (v, CC, maxx, maxy, orgx, orgy, ss);
  280.             break;
  281.         case HDT_LAMPS:
  282.             show_lamps (v, CC, maxx, maxy, orgx, orgy, ss);
  283.             break;
  284.         default:
  285.             show_view (v, st.hdd[i].type, 1);
  286.             break;
  287.         }
  288.         ident (i+1, orgx, orgy, maxx, maxy, ss);
  289.         buffer_close ();
  290.         st.hdd[i].bufs[1-st.which_buffer] = st.buf[HEAD];
  291.         st.buf[HEAD] = st.buf[TAIL] = 0;
  292.     }
  293.     STATS_TIMEHDD += Tm->Interval (TMR_STOP, 10000L)
  294.                         - (STATS_TIME3D - t27);
  295. }
  296.